package com.tanglon.controller;

import com.tanglon.domain.ResponseResult;
import com.tanglon.domain.dto.AddRoleDTO;
import com.tanglon.domain.dto.RoleStatusDTO;
import com.tanglon.domain.dto.UpdateRoleDTO;
import com.tanglon.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/system/role")
public class RoleController {

    @Autowired
    private RoleService roleService;

    @GetMapping("/list")
    public ResponseResult roleList(Integer pageNum, Integer pageSize, String roleName,String status){
        return roleService.roleList(pageNum,pageSize,roleName,status);
    }


    @PutMapping("/changeStatus")
    public ResponseResult changeStatus(@RequestBody RoleStatusDTO roleStatusDTO){
        return roleService.changeStatus(roleStatusDTO);
    }

    /**
     * 添加角色权限
     * @param addRoleDTO
     * @return
     */
    @PostMapping
    public ResponseResult addRole(@RequestBody AddRoleDTO addRoleDTO){
        return roleService.addRole(addRoleDTO);
    }

    @GetMapping("/{id}")
    public ResponseResult roleDetail(@PathVariable Integer id){
        return roleService.roleDetail(id);
    }

    @PutMapping
    public ResponseResult updateRole(@RequestBody UpdateRoleDTO updateRoleDTO){
        return roleService.updateRole(updateRoleDTO);
    }

    @DeleteMapping("/{id}")
    public ResponseResult deleteRole(@PathVariable Integer id){
        return roleService.deleteRole(id);
    }

    @GetMapping("/listAllRole")
    public ResponseResult roleListAll(){
        return roleService.roleListAll();
    }
}
